﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TaskResultBase.cs" company="DHGMS Solutions">
//   Copyright 2004-2015 DHGMS Solutions
//   
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//   
//       http://www.apache.org/licenses/LICENSE-2.0
//   
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
// </copyright>
// <summary>
//   Represents the base task result
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Dhgms.TplHelper.Model.Info
{
        using System;
        using System.ComponentModel.DataAnnotations;
        using System.Diagnostics;
        using System.Diagnostics.CodeAnalysis;
        using System.Runtime.Serialization;
        using System.Xml;
        using System.Xml.Linq;

        // ********** WARNING **********
        // This code is automatically generated! Any Changes you make to this file will be lost!
        // To make changes edit the corresponding .tt file!

        /// <summary>
        /// Represents the base task result
        /// </summary>
        [DataContract]
        public class TaskResultBase
// ReSharper disable RedundantNameQualifier
            : Dhgms.DataManager.Model.Info.InfoBase<TaskResultBase>
// ReSharper restore RedundantNameQualifier
        {
        #region fields
        #endregion

        // ********** WARNING **********
        // This code is automatically generated! Any Changes you make to this file will be lost!
        // To make changes edit the corresponding .tt file!

        /// <summary>
        /// Initializes a new instance of the <see cref="TaskResultBase"/> class.
        /// </summary>
        public TaskResultBase()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TaskResultBase"/> class.
        /// </summary>
        /// <param name="other">
        /// Object to copy
        /// </param>
        public TaskResultBase(TaskResultBase other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            this.Name = other.Name;
            this.Started = other.Started;
            this.Finished = other.Finished;
        }

        // ********** WARNING **********
        // This code is automatically generated! Any Changes you make to this file will be lost!
        // To make changes edit the corresponding .tt file!

        /// <summary>
        /// Initializes a new instance of the <see cref="TaskResultBase"/> class.
        /// </summary>
        /// <param name="name">Name of the task</param>
        /// <param name="started">Timestamp of when the task started</param>
        /// <param name="finished">Timestamp of when the task finished</param>
        public TaskResultBase(
            string name,
            DateTime started,
            DateTime finished)
            {
            this.Name = name;
            this.Started = started;
            this.Finished = finished;
        }

        #region properties
        /// <summary>
        /// Gets or sets Name of the task
        /// </summary>
        [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1121:UseBuiltInTypeAlias", Justification = "Reviewed. Suppression is OK here.")]
        [DataMember(IsRequired = true, Order = 1)]
        [Required]
        public string Name
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets Timestamp of when the task started
        /// </summary>
        [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1121:UseBuiltInTypeAlias", Justification = "Reviewed. Suppression is OK here.")]
        [DataMember(IsRequired = true, Order = 2)]
        [Required]
[Range(typeof(System.DateTime), "", "")]
        public DateTime Started
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets Timestamp of when the task finished
        /// </summary>
        [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1121:UseBuiltInTypeAlias", Justification = "Reviewed. Suppression is OK here.")]
        [DataMember(IsRequired = true, Order = 3)]
        [Required]
[Range(typeof(System.DateTime), "", "")]
        public DateTime Finished
        {
            get;
            set;
        }

            /// <summary>
            /// Gets a header record for use for something like a CSV file
            /// </summary>
            /// <returns>a collection of strings representing the header record</returns>
            public override System.Collections.Generic.IList<string> HeaderRecord
            {
                get
                {
                    var result = new System.Collections.Generic.List<string>
                    {
                        "Name",
                        "Started",
                        "Finished"
                    };

                    return result;
                }
            }

        #endregion

        #region IComparable methods

        // ********** WARNING **********
        // This code is automatically generated! Any Changes you make to this file will be lost!
        // To make changes edit the corresponding .tt file!

        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="other">
        /// The instance to compare to
        /// </param>
        /// <returns>
        /// 0 if equal, otherwise non zero
        /// </returns>
        public override int CompareTo(TaskResultBase other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            // Name
            var checkResult = string.CompareOrdinal(this.Name, other.Name);

            if (checkResult != 0)
            {
                return (checkResult > 0) ? 1 : -1;
            }

            // Started
            checkResult = this.Started.CompareTo(other.Started);

            if (checkResult != 0)
            {
                return (checkResult > 0) ? 2 : -2;
            }

            // Finished
            checkResult = this.Finished.CompareTo(other.Finished);

            if (checkResult != 0)
            {
                return (checkResult > 0) ? 3 : -3;
            }

            return 0;
        }

        #endregion
#region IEquatable methods
            /// <summary>
            /// Checks if the current instance matches another of the same type
            /// </summary>
            /// <param name="other">object to compare</param>
            /// <returns>true if equal, otherwise false</returns>
            public override bool Equals(TaskResultBase other)
            {
                return this.CompareTo(other) == 0;
            }

#endregion

    #region our methods

        /// <summary>
        /// Gets the hash code for the object
        /// </summary>
        /// <returns>hash code</returns>
        public override int GetHashCode()
        {
            return
                (this.Name != null ? this.Name.GetHashCode() : 0)
                ^ this.Started.GetHashCode()
                ^ this.Finished.GetHashCode();
        }

        /// <summary>
        /// Checks a table to ensure it meets the required schema
        /// </summary>
        public override void DoTableValidation()
        {
        }

            /// <summary>
            /// Gets a collection of string data for use for something like a CSV file
            /// </summary>
            /// <returns>a collection of strings representing the data record</returns>
            public override System.Collections.Generic.IList<string> ToStringArray()
            {
                var result = new System.Collections.Generic.List<string>
                {
                    this.Name,
                    this.Started.ToString("yyyy-MM-dd HH:mm:ss"),
                    this.Finished.ToString("yyyy-MM-dd HH:mm:ss")
                };

                return result;
            }

            /// <summary>
            /// Adds an XML Element to an XML Writer
            /// </summary>
            /// <param name="writer">
            /// The XML writer to add the element to.
            /// </param>
            /// <param name="parentElementName">
            /// The name for the parenet element being produced.
            /// </param>
            public override void DoXmlElement(
                    System.Xml.XmlWriter writer,
                    string parentElementName)
            {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            if (string.IsNullOrEmpty(parentElementName) || parentElementName.Trim().Length == 0)
            {
            throw new ArgumentNullException("parentElementName");
            }

                writer.WriteStartElement(parentElementName);

                // Name
                this.DoChildXmlCDataElement(writer, "Name", this.Name);

                // Started
                this.DoChildXmlCDataElement(writer, "Started", this.Started.ToString("yyyy-MM-dd HH:mm:ss"));

                // Finished
                this.DoChildXmlCDataElement(writer, "Finished", this.Finished.ToString("yyyy-MM-dd HH:mm:ss"));

                writer.WriteEndElement();
            }

        /// <summary>
        /// Checks this instance against another to see where there are differences
        /// </summary>
        /// <param name="other">other instance to compare</param>
        /// <returns>summary of where there are differences</returns>
// ReSharper disable RedundantNameQualifier
        public Dhgms.TplHelper.Model.Difference.TaskResultBaseDifference GetDifferences(TaskResultBase other)
// ReSharper restore RedundantNameQualifier
        {
            if (other == null)
            {
                throw new System.ArgumentNullException("other");
            }

            // Name
            var checkResult = string.CompareOrdinal(this.Name, other.Name);

            var nameDifferent = checkResult != 0;

            // Started
            checkResult = this.Started.CompareTo(other.Started);

            var startedDifferent = checkResult != 0;

            // Finished
            checkResult = this.Finished.CompareTo(other.Finished);

            var finishedDifferent = checkResult != 0;

// ReSharper disable RedundantNameQualifier
            return new Dhgms.TplHelper.Model.Difference.TaskResultBaseDifference(
// ReSharper restore RedundantNameQualifier
                nameDifferent,
                startedDifferent,
                finishedDifferent);
        }

        /// <summary>
        /// Gets the CDSL that defines the OData Vocabularies for this class
        /// </summary>
        public static XmlReader GetOdataVocabularies()
        {
            // Name

            // Started

            // Finished

        var schema = new XElement(
            "Schema",
            new XAttribute("Namespace", "Dhgms.TplHelper"),
            new XAttribute("xmlns", "http://schemas.microsoft.com/ado/2009/11/edm"),
            // using directive
            new XElement(
                "Using",
                new XAttribute("Namespace", "Org.OData.Validation.V1"),
                new XAttribute("Alias", "Validation"),
                new XElement(
                    "Annotations",
                    new XAttribute("Target", "Dhgms.TplHelper.TaskResultBase/Name")),
                new XElement(
                    "Annotations",
                    new XAttribute("Target", "Dhgms.TplHelper.TaskResultBase/Started")),
                new XElement(
                    "Annotations",
                    new XAttribute("Target", "Dhgms.TplHelper.TaskResultBase/Finished"))));

        Debug.Assert(schema.Document != null, "schema.Document != null");
        return schema.Document.CreateReader();
        }
        #endregion
            /// <summary>
            /// The on disposing event
            /// </summary>
            protected override void OnDisposing()
            {
            }
    }
}
